class Solution {
public:
    string minWindow(string s, string t) {
        int hash1[128]={0};
        int kinds=0;//字符串t的有效字符种类个数
        for(auto e:t)
        {
            if(hash1[e]==0)
            {
                kinds++;
            }
            hash1[e]++;
        }
        int hash2[128]={0};
        int len=INT_MAX;
        int begin=-1;
        for(int left=0,right=0,count=0;right<s.size();right++)
        {
            char in=s[right];
            hash2[in]++;
            if(hash2[in]==hash1[in])
            count++;
            while(count==kinds)
            {
                if(right-left+1<len)
                {
                    len=right-left+1;
                    begin=left;
                }
                char out=s[left++];
                if(hash1[out]==hash2[out])
                {
                    count--;
                }
                hash2[out]--;
            }
        }
        if(begin==-1)return "";
        else
        return s.substr(begin,len);
    }
};